<%@page import="com.glaivelee.HTMLFilter"%>
<%@page import="com.glaivelee.firstRefactor.ClearCssAndLabel"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.util.regex.*"%>
<%@page import="com.glaivelee.abstracts.chooseType"%>
<%@page import="com.glaivelee.firstRefactor.chooseType_Links"%>
<%@page import="com.glaivelee.firstRefactor.chooseType_Images"%>
<jsp:useBean id="HTMLFilter" class="com.glaivelee.HTMLFilter"
	scope="page" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>RegexTest</title>
		<script>
function checkEmpty(){
		if(post.editer1.value == ""){
			alert("似乎内容忘记填写了吧!");
			post.editer1.focus();
			return false;
		}
		return true;
	}
</script>
		<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
		<script type="text/javascript">
    window.onload = function (){
        CKEDITOR.replace("editer1");
        CKEDITOR.config.height = "500px";
        CKEDITOR.config.width = "608px";
    }
</script>

		<script language="javascript">
function CheckMyForm()
{
	var txt = post.ImagesCount.value;
	if(checknumber(txt))
	{
		txt = "";
		return false;
	}
	return true;
}
function checknumber(String)
{
	var Letters = "1234567890";
	var i;
	var c;
	for( i = 0; i < String.length; i ++ )
	{
		c = String.charAt( i );
		if (Letters.indexOf( c ) ==-1)
		{
			return true;
		}
	}
	return false;
}
</script>
	</head>

	<body>

		<form name="post" method="post" action="">
			<textarea name="editer1" id="editer1"></textarea>
			<br />
			<input type="hidden" name="action" value="submitValue" />
			<br />
			<input type="radio" name="FilterType" value="links" checked="checked" />
			链接
			<input type="radio" name="FilterType" value="Images" />
			图片
			<input type="text" onkeyup="value=value.replace(/[^\d]/g,'')"
				name="ImagesCount" />
			<!-- <input type="radio" name="FilterType" value="background" />背景图片<br/> -->
			<input type="radio" name="FilterType" value="clearStyle" />
			clearStyle
			<br />
			<input type="submit" value="SUB" style="width: 270px; height: 50px;" />
		</form>
	</body>
</html>
<%
	request.setCharacterEncoding("UTF-8");
	if ((request.getParameter("action") != null)
			&& !(request.getParameter("action").equals(""))) {
		response.setCharacterEncoding("UTF-8");

		String srcValue = request.getParameter("editer1").toLowerCase();
		String filterType = request.getParameter("FilterType");
		int ImagesCount = 1;

		try {
			ImagesCount = Integer.parseInt(request
					.getParameter("ImagesCount"));
		} catch (Exception e) {
			ImagesCount = 1;
		}

		/*new Method*/
		chooseType ct = null;
		if (filterType.equals("links")) {
			ct = new chooseType_Links(srcValue);
		} else if (filterType.equals("Images")) {
			ct = new chooseType_Images(srcValue, ImagesCount);
		} else if (filterType.equals("clearStyle")) {
			ct = new ClearCssAndLabel(srcValue);
		}
		
		String resCode = ct.exeRex();
		
		// Translate HTMLResource 
		boolean EXEC_HTMLTranslate = (1 == 9) ? true : false;
		
		if(EXEC_HTMLTranslate){
			resCode = chooseType.getHTMLResource(resCode);
		}
				
		out.print(resCode);
	}
	
	
%>
